package com.alks.function.mapper.chengKong;

import com.alks.entity.data.entity.YfColorDetail;
import com.alks.function.data.dto.chengKong.assort.ColorSystemDto;
import com.alks.function.data.dto.chengKong.assort.YfColorDetail2Dto;
import com.alks.function.data.dto.chengKong.assort.YfColorDetailDto;
import com.alks.function.data.request.chengKong.ColorSystemRequest;
import com.alks.function.data.request.chengKong.MonochromeRequest;
import com.alks.function.data.request.chengKong.MonochromeRequest2;
import com.alks.function.data.request.chengKong.PolychromeRequest;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mapstruct.Mapper;

import java.util.List;

@Mapper
public interface ColorAttributeMapper {

    /**
     * 单色系明细
     * @param request
     * @return
     */
    List<YfColorDetailDto> getMonochromeList(MonochromeRequest request);

    /**
     * 查询国际标准色卡
     * @param pantone
     * @return
     */
    @Select("select PANTONE from YF_COLOR_DETAIL where COLOR_SYSTEM='单色系' and PANTONE=#{pantone}")
    String getPantone(String pantone);

    /**
     * 查询颜色
     * @param color
     * @return
     */
    YfColorDetailDto getColor(@Param("color") String color);

    /**
     * 获取颜色编码
     * @return
     */
    @Select("SELECT CONCAT(#{str}, LPAD(MAX(CAST(SUBSTRING(COLOR_CODE, 2) AS UNSIGNED)) + 1, 4, '0')) AS colorCode " +
            "FROM YF_COLOR_DETAIL " +
            "WHERE COLOR_CODE  LIKE CONCAT(#{str},'%')")
    String getMonochromeColorCode(String str);

    /**
     * 单色添加
     * @param yfColorDetail
     * @return
     */
    int addMonochrome(YfColorDetail yfColorDetail);

    /**
     * 单色系修改
     * @param yfColorDetail
     * @return
     */
    int updateMonochrome(YfColorDetail yfColorDetail);

    /**
     * 单色系删除
     * @param request
     * @return
     */
    @Delete("delete from YF_COLOR_DETAIL where COLOR_SYSTEM=#{colorSystem} and COLOR_NAME=#{colorName}")
    int delMonochrome(MonochromeRequest2 request);

    /**
     * 插色系明细
     * @param request
     * @return
     */
    List<YfColorDetail2Dto> getPolychromeList(PolychromeRequest request);

    /**
     * 插色系材料颜色
     * @param colorName
     * @return
     */
    @Select("select COLOR_NAME from YF_COLOR_DETAIL where COLOR_NAME=#{colorName}")
    String getColorName(String colorName);

    /**
     * 选择颜色
     * @param request
     * @return
     */
    List<ColorSystemDto> getColorSystemList(ColorSystemRequest request);

    /**
     * 查询颜色是否存在
     * @param mtlColor
     * @return
     */
    ColorSystemDto getYfColorDetail(String mtlColor);

    /**
     * 查询颜色是否在BOM中
     * @param colorName
     * @return
     */
    Integer getYfBomMtl(String colorName);
}
